package codingforgreat.lchot150;

public class Lc038 {
    public String countAndSay(int n) {
        if(n == 1){
            return "1";
        }else
        if(n < 1){
            return "";
        }else{
            char[] s = countAndSay(n - 1).toCharArray();
            int count = 1;
            StringBuilder sb = new StringBuilder();
            for(int i = 1;i < s.length;i++){
                if(s[i] == s[i - 1]){
                    count++;
                }else{
                    sb.append(String.valueOf(count));
                    sb.append(String.valueOf(s[i - 1]));
                    count = 1;
                }
            }
            sb.append(String.valueOf(count));
            sb.append(String.valueOf(s[s.length - 1]));
            return sb.toString();

        }

    }
}
